﻿#region Copyright © 2008 by Christian Rodemeyer
// $HeadURL: http://rodemeyer.googlecode.com/svn/trunk/Rodemeyer/Collections/HashSet.cs $
// $Revision: 26 $
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Rodemeyer.Collections
{
    //[Obsolete("Use the new HashSet<T> class of the framework 3.5 instead")]
    public class HashSet<T> : ICollection<T>
    {
        Hashtable set = new Hashtable();

        public bool Add(T item)
        {
            if (Contains(item)) return false;

            set.Add(item, null);
            return true;
        }

        void ICollection<T>.Add(T item)
        {
            Add(item);
        }

        public void Clear()
        {
            set.Clear();
        }

        public bool Contains(T item)
        {
            return set.ContainsKey(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            set.Keys.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return set.Count; }
        }

        public bool IsReadOnly
        {
            get { return set.IsReadOnly; }
        }

        public bool Remove(T item)
        {
            bool result = set.ContainsKey(item);
            set.Remove(item);
            return result;
        }

        public IEnumerator<T> GetEnumerator()
        {
            foreach (T item in set.Keys)
            {
                yield return item;
            }
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return set.Keys.GetEnumerator();
        }

     

    }
}
